/*
 * Copyright © Stéphane Raimbault <stephane.raimbault@gmail.com>
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 */

#ifndef MODBUS_TCP_H
#define MODBUS_TCP_H

#include "modbus.h"

#ifdef __cplusplus
extern "C" {
#endif

#define MODBUS_TCP_DEFAULT_PORT 502
#define MODBUS_TCP_SLAVE        0xFF

/* Modbus_Application_Protocol_V1_1b.pdf Chapter 4 Section 1 Page 5
 * TCP MODBUS ADU = 253 bytes + MBAP (7 bytes) = 260 bytes
 */
#define MODBUS_TCP_MAX_ADU_LENGTH 260

modbus_t* modbus_new_tcp(const char* ip_address, int port);
int modbus_tcp_listen(modbus_t* ctx, int nb_connection);
int modbus_tcp_accept(modbus_t* ctx, int* s);

modbus_t* modbus_new_tcp_pi(const char* node, const char* service);
int modbus_tcp_pi_listen(modbus_t* ctx, int nb_connection);
int modbus_tcp_pi_accept(modbus_t* ctx, int* s);

#ifdef __cplusplus
}
#endif

#endif /* MODBUS_TCP_H */
